﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

namespace Code
{
    public class StatisticController
    {
        StatisticDataAccess _dataAccess;

        public StatisticController()
        {
            _dataAccess = new StatisticDataAccess();
        }

        public List<int> GetYearList()
        {
            DataTable dt = _dataAccess.GetYearList();

            List<int> yearList = new List<int>();

            if ((dt != null) && (dt.Rows.Count > 0))
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    int year;
                    String str = dt.Rows[i][0].ToString();
                    if (str != "")
                    {
                        year = Convert.ToInt32(str);
                        yearList.Add(year);
                    }
                }

                return yearList;
            }
            else
                return null;
        }

        public List<int> GetMonthList(int year)
        {
            DataTable dt = _dataAccess.GetMonthList(year);

            List<int> monthList = new List<int>();

            if ((dt != null) && (dt.Rows.Count > 0))
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    String str = "";
                    int month ;
                    str = dt.Rows[i][0].ToString();
                    if (str != "")
                    {
                        month = Convert.ToInt32(str);
                        monthList.Add(month);
                    }
                }

                return monthList;
            }
            else
                return null;
        }

        public int GetStatisticWithMonth(int month, int year)
        {
            DataTable dt = _dataAccess.GetStatisticWithMonth(month,year);

            if ((dt != null) && (dt.Rows.Count > 0))
            {
                String str = dt.Rows[0][0].ToString();
                if (str != "")
                    return Convert.ToInt32(dt.Rows[0][0].ToString());
                else
                    return 0;
            }
            else
                return 0;
        }
    }
}
